<?php
/**
 * FastApp.
 * 8/13/24
 * @Author 深色的海 (wx:deepsea_0024)
 * @Contact telegram:deepsea159
 */

namespace App\Game\Api\Controller;

use App\Fastapp\Api\Controller\ApiController;
use App\Game\Api\Service\Platform\FiverscanService;
use App\Game\Api\Service\Platform\GamepgService;
use App\Game\Api\Service\Platform\NexusggrService;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;

#[Controller('/')]
class CallbackController extends ApiController
{
    #[PostMapping('gamePgBalance')]
    public function gamePgBalance(): ResponseInterface
    {
        return $this->getResponse()
            ->withAddedHeader('content-type', 'application/json; charset=utf-8')
            ->withBody(new SwooleStream(json_encode(GamepgService::getBalance($this->request->all()))));
    }

    #[PostMapping('gamePg')]
    public function gamePg(): ResponseInterface
    {
        return $this->getResponse()
            ->withAddedHeader('content-type', 'application/json; charset=utf-8')
            ->withBody(new SwooleStream(json_encode(GamepgService::transaction($this->request->all()))));
    }

    #[PostMapping('gold_api')]
    public function goldApi(): ResponseInterface
    {
        $data = [];
        if (FiverscanService::getConfig()['agent_code'] == $this->request->input('agent_code')) $data = FiverscanService::transaction($this->request->all());
        if (NexusggrService::getConfig()['agent_code'] == $this->request->input('agent_code')) $data = NexusggrService::transaction($this->request->all());
        return $this->getResponse()
            ->withAddedHeader('content-type', 'application/json; charset=utf-8')
            ->withBody(new SwooleStream(json_encode($data)));
    }
}